<template>
    <div class="big" v-for="(item, index) in DocListFilter" :key="'doc' + index">
        <div class="top" >
            <img :src="item.avatar" alt="">
            <span class="span1" >{{item.name}}</span>
            &nbsp;
            <span class="span2">{{item.level}}</span>
            <br>
            <span class="span3">{{parseInt(Math.random()*10000)}}</span>
            &nbsp;
            <span class="span4">接诊量</span>
            <p class="yuyue" @click="toConfirm(item.name)">预约</p>
        </div>
        <p class="bottom" style=" margin-top: 5px; font-size: 14px; text-align: left; ">
            {{ item.introduce }}
        </p>
    </div>

</template>

<script setup lang="ts">
import { getDoctorList , getDepList } from '@/api/api';
import { ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import router from "@/router";

const route = useRoute()
const depid = ref(0)
const DocList = ref([])
// const random = parseInt(Math.random()*10000)
const DocListFilter = ref([])
// 点击子科室跳转到挂号页面并携带点击参数
console.log();

// 定义一个空的depid并赋值item的depid，返回true方能完成find功能
// 查找对应科室的id并返回，随后获取所有医生数据并过滤到该科室的医生
(async function () {
    // 设置默认
    const level = route.query.type && decodeURI(route.query.type) === "专家预约" ? 1 : 0

    // console.log(route.query);
    
    const resDep = await getDepList()

    console.log(resDep);
    
    resDep.data.result.data.find(item => {
        depid.value = item.depid
        return item.name === decodeURI(route.query.name)
    })
    // 获取所有医生列表
    const resDoc = await getDoctorList()
    console.log(resDoc);
    
    DocList.value = resDoc.data.data.data.filter(item => item.depid === depid.value)
    // console.log(222,DocList.value);

    // 按挂号类型筛选医生
    DocListFilter.value = DocList.value.filter(item => {
        if (level) {
            return item.level === "主任医师"
        } else {
            return item.level !== "主任医师"
        }
    })
    console.log(123,DocListFilter.value);
    // console.log(111,DocList.value);

})()

// const doctorList = ref([])
// onMounted(async() => {
    
//     const doctorRes = await getDoctorList()
//     // console.log(doctorRes);
//     doctorList.value = doctorRes.data.data
//     // console.log(doctorList.value);
// })

// doctorList.value.forEach(item => {
//     const res = await 
// })

// 点击跳转确认预约
const toConfirm = (name) => {
    router.push({
        path: '/confirm',
        query: {
            name: encodeURI(name)
        }
    })
    console.log(name);
}
</script>

<style lang="scss" scoped>
.big {
    width: 95vw;
    height: 20vh;
    // border-bottom: rgb(230, 229, 229) solid 3px;
    margin:15px auto;
    background-color: rgb(247, 247, 247);
    border-radius: 18px;

    .top {
        width: 95%;
        height: 200px;
        padding: 0 18px;
       

        img {
            width: 160px;
            height: 160px;
            float: left;
            border-radius: 15px;
            margin-top: 26px;
        }

        .span1{
            font-size: 26px;
            font-weight: bold;
            margin-left: 30px;
        }

        .span2{
            font-size: 12px;
            background-color: rgb(234, 234, 234);
            padding: 5px 10px 5px 10px;
        }

        .span3{
            font-size: 16px;
            color: red;
            margin-left: 30px;
        }

        .span4{
            font-size: 18px;
            color: rgb(178, 176, 176);
            margin-left: 35px;
        }

        .yuyue{
            font-size: 28px;
            width: 100px;
            height: 55px;
            text-align: center;
            line-height: 55px;
            background-color: rgb(0, 183, 255);
            float: right;
            border-radius: 25%;
        }
    }

    .bottom{
        display: -webkit-box;
        font-size: 20px;
        text-indent: 1rem;
        padding-left:10px;
        overflow: hidden;
        word-wrap: break-word;
        white-space: normal !important;
        text-overflow: ellipsis;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        
    }
}
</style>